package com.dz.server.service.impl;

import com.dz.server.pojo.User;
import com.dz.server.mapper.UserMapper;
import com.dz.server.service.UserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author dz
 * @since 2022-03-22
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public User selectUserByName(String username) {
        return userMapper.selectUserByName(username);
    }

    @Override
    public boolean registerUser(User user, String repassword) {
        //通过用户名查询用户
        Integer count = userMapper.selectCount(user.getUsername());
        //说明存在相同名字的人  或者 两次输入密码不相同
        if (count!=0 || !user.getPassword().equals(repassword))
            return false;
        userMapper.insert(user);
        return true;
    }

    @Override
    public User selectUser(String username, String password) {
        User user = userMapper.selectUser(username, password);
        return user;
    }
    //修改用户信息
    public boolean updateUser(User user,String repassword){
        //通过用户名查询用户
        Integer count = userMapper.selectCount(user.getUsername());
        //说明存在相同名字的人  或者 两次输入密码不相同
        if (count!=0 || !user.getPassword().equals(repassword))
            return false;
        userMapper.updateById(user);
        return true;
    }
}
